package com.kuaiditu.assistant.base;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.kuaiditu.assistant.App;
import com.kuaiditu.assistant.dagger.components.AppComponent;
import com.kuaiditu.assistant.dagger.modules.ActivityModule;


public abstract class BaseFragment extends Fragment {


    protected Context mContext;

    protected  String title = "最近发贴";



    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {



        mContext = getContext();
        initInjector();
        getBundle(getArguments());
        initUI(view);
        initData();
        super.onViewCreated(view, savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return onCreateContentView(inflater);



    }

    public View onCreateContentView(LayoutInflater inflater) {
        return inflater.inflate(initContentView(), null);
    }



    protected AppComponent getApplicationComponent() {
        return ((App) getActivity().getApplication()).getApplicationComponent();
    }

    protected ActivityModule getActivityModule() {
        return new ActivityModule(getActivity());
    }


    public abstract void initInjector();

    public abstract int initContentView();

    /**
     * 得到Activity传进来的值
     */
    public abstract void getBundle(Bundle bundle);

    /**
     * 初始化控件
     */
    public abstract void initUI(View rootView);

    /**
     * 在监听器之前把数据准备好
     */
    public abstract void initData();


    public String getTitle() {
        return title;
    }
}
